﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using System.Data;
using BEGDC.Utility.NHibernate;
using Castle.Services.Transaction;
using System.Collections;
using System.Xml;
using Castle.Facilities.NHibernateIntegration;

namespace BEGDC.PreContract.BLL
{
	public partial class CAT: ICAT
	{
        public BEGDC.PreContract.DAL.CAT GetCATByName(string catCode)
        {
            BEGDC.PreContract.DAL.CAT cat = BEGDC.PreContract.DAL.CAT.FindFirst(new NHibernate.Expression.EqExpression(BEGDC.PreContract.DAL.CAT.CONST_CATCode, catCode));

            return cat;

        }

        public BEGDC.PreContract.DAL.CAT GetCATByShorteningCode(string shorteningCode)
        {
            BEGDC.PreContract.DAL.CAT cat = BEGDC.PreContract.DAL.CAT.FindFirst(new NHibernate.Expression.LikeExpression(BEGDC.PreContract.DAL.CAT.CONST_CATCode_Shortening, string.Format("%{0}%",shorteningCode)));

            return cat;
        }

        //Joan.lu 2008-09-19
        //Get Active CAT dimention by user permission
        public DataTable GetCATByPermission(long employeeID)
        {
            using (ISession session = factory.OpenSession())
            {
                string strSql = "SELECT a.* FROM dbo.CAT a INNER JOIN dbo.CATAssignment b ON a.CATID=b.CATID WHERE a.Active=1 AND b.EmployeeID=" + employeeID.ToString() + " ORDER BY a.SortNumber";

                DataTable dtSearch = DAO.ExecuteDataTable(session, strSql);

                return dtSearch;
            }
        }

        //Edwin.fan 2008-9-23
        //Get the province with the max ProvinceId
        public DataTable GetMaxCAT()
        {
            using (ISession session = factory.OpenSession())
            {
                string strSql = "SELECT max(CATID) FROM CAT";

                DataTable dtSearch = DAO.ExecuteDataTable(session, strSql);

                return dtSearch;
            }

        }
	}
}



